package com.proxy.common.disruptor;

import com.lmax.disruptor.EventTranslatorOneArg;
import com.lmax.disruptor.RingBuffer;

/**
 * Created by liufish on 16/12/24.
 */
public class LongEventProducerWithTranslator {

    private static final EventTranslatorOneArg<LongEvent, String> TRANSLATOR = new EventTranslatorOneArg<LongEvent, String>() {
        public void translateTo(LongEvent event, long sequence,String message) {
            event.setMessage(message);
        }
    };
    private final RingBuffer<LongEvent> ringBuffer;

    public LongEventProducerWithTranslator(RingBuffer<LongEvent> ringBuffer) {
        this.ringBuffer = ringBuffer;
    }

    public void onData(String message) {
        ringBuffer.publishEvent(TRANSLATOR, message);
    }
}
